package de.medizin.uni.halle.irm;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {    
    DatabaseHelper(Context context){
    	super(context, "born", null, 3);
    }	
	 @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("drop table if exists patients;");
        db.execSQL("CREATE TABLE patients (" +
        		"_id INTEGER primary key autoincrement," +		
        		"sid INTEGER," +		
        		"gender INTEGER," +
        		"firstname TEXT," + 
        		"lastname TEXT," +
        		"phone TEXT," +
        		"mobile_phone TEXT," +
        		"email TEXT," + 
        		"address TEXT,"+
        		"zip TEXT,"+
        		"city TEXT,"+
        		"contacttype INTEGER," +			// 0=SMS, 1=EMAIL, 2=BRIEF, 3=PHONE
        		"startdate INTEGER," +		// Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.
        		//"history TEXT" +			// "6,8,9" Liste von msgid (nur als Cache f�r schnelleren Zugriff)
        		"rank INTEGER);");			// aktueller Stand im Betreuungsplan

        
        // create planning times
	    db.execSQL("drop table if exists plans;");
	    db.execSQL("CREATE TABLE plans (" +
	    		"_id INTEGER primary key autoincrement," +
	    		"patient_id INTEGER," +
	    		"contacttype TEXT," +	
	    		"date TEXT);" 			// ab welchem Datum
	    );	
	    
	    db.execSQL("drop table if exists history;");
	    db.execSQL("CREATE TABLE history (" +
	    		"_id INTEGER primary key autoincrement," +
	    		"sid INTEGER," +
	    		"historytype TEXT,"+
	    		"type TEXT," +
	    		"content TEXT," +
	    		"evaluation TEXT," +
	    		"comment Text," +
	    		"date DATETIME DEFAULT CURRENT_TIMESTAMP );" 			
	    );	 
	    db.execSQL("drop table if exists qustions;");
	    db.execSQL("CREATE TABLE questions (" +
	    		"_id INTEGER primary key autoincrement ," +
	    		"question TEXT,"+
	    		"token TEXT," +
	    		"position INTEGER,"+
	    		"state TEXT );" 			
	    );	 
	    db.execSQL("drop table if exists answers;");
	    db.execSQL("CREATE TABLE answers (" +
	    		"_id INTEGER primary key autoincrement," +
	    		"question_id INTEGER,"+
	    		"answer TEXT,"+
	    		"token TEXT);" 			
	    );	  
	    db.execSQL("drop table if exists settings;");
	    db.execSQL("CREATE TABLE settings (" +
	    		"setting TEXT primary key," +
	    		"parameter TEXT);"	
	    );	
    }

 	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("drop table if exists patients;");
        db.execSQL("CREATE TABLE patients (" +
        		"_id INTEGER primary key autoincrement," +		
        		"sid INTEGER," +		
        		"gender TEXT," +
        		"firstname TEXT," + 
        		"lastname TEXT," +
        		"phone TEXT," +
        		"email TEXT," + 
        		"address TEXT,"+
        		"zip TEXT,"+
        		"city TEXT,"+
        		"contacttype INTEGER," +			// 0=SMS, 1=EMAIL, 2=BRIEF, 3=PHONE
        		"startdate INTEGER," +		// Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.
        		//"history TEXT" +			// "6,8,9" Liste von msgid (nur als Cache f�r schnelleren Zugriff)
        		"rank INTEGER);");			// aktueller Stand im Betreuungsplan

        
        // create planning times
	    db.execSQL("drop table if exists plans;");
	    db.execSQL("CREATE TABLE plans (" +
	    		"_id INTEGER primary key autoincrement," +
	    		"patient_id INTEGER," +
	    		"contacttype TEXT," +	
	    		"date TEXT);" 			// ab welchem Datum
	    );	
	}
}
